package Stream;

import java.util.stream.Stream;

public class demo2 {
    public static void main(String[] args) {
        //获取一个stream流
        Stream<Integer> stream1 = Stream.of(1, 2, 3, 4, 5, 6);

        stream1.forEach(i-> System.out.print(i));
        System.out.println("\n========");
        Stream<Integer> stream2 = Stream.of(1, 2, 3, 4, 5, 6);
        //统计个数
        long count = stream2.count();
        System.out.println(count);
        //打印前面几个
        Stream<Integer> stream3 = Stream.of(1, 2, 3, 4, 5, 6);
        Stream<Integer> limit = stream3.limit(3);
        limit.forEach(i->{
            System.out.print(i);
        });
        System.out.println("\n==========");
        //跳过前面几个
        Stream<Integer> stream4 = Stream.of(1, 2, 3, 4, 5, 6);
        Stream<Integer> skip = stream4.skip(4);
        skip.forEach(i-> System.out.print(i));
        System.out.println("\n=========");
        //将String类型转换为Integer类型
        Stream<String> stream = Stream.of("1", "2", "3", "4", "5");
        Stream<Integer> stream5 = stream.map(name -> {
            return Integer.parseInt(name);
        });
        stream5.forEach(i->{
            System.out.print(i);
        });
        System.out.println("\n===========");
        //合并流
        Stream<String> stream6 = Stream.of("1", "2", "3", "4", "5");
        Stream<String> stream7 = Stream.of("小明", "小军", "小刘");
        Stream<String> concat = Stream.concat(stream6, stream7);
        concat.forEach(s->{
            System.out.print(s);
        });
    }
}
